import 'package:app/common/index.dart';
import 'package:app/router/router.dart';
import 'package:app/store/index.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';

// 权限相关方法
class UserHelper {
  // 检查用户是否登录
  static bool checkLogin(BuildContext context) {
    UserModel user = Provider.of<UserModel>(context, listen: false);
    if (user.token != null && user.token != "") {
      return true;
    }
    return false;
  }

  // 退出登录
  static Future<void> loginOut(BuildContext context) async {
    // ApiService(context).loginOut();
    // TODO: 退出登录后将token销毁，缓存也要清楚
    bool isClear = await Global.clearSharedPreferences();
    Global.clearProfile();
    if (isClear) {
      router.go("/login");
    }
  }
}
